package bank

import (
	"LogisticsPort/model"
	"LogisticsPort/sql"
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
)

//一般费用单、其他收入

func incomeExpenseAdd(c *gin.Context) {
	sql.HttpAdd(c, &model.BankIncomeExpense{}, nil)
}

func incomeExpenseUpdates(c *gin.Context) {
	sql.HttpUpdates(c, &model.BankIncomeExpense{}, nil)
}

func incomeExpenseDelete(c *gin.Context) {
	sql.HttpDeleteById(c, &model.BankIncomeExpense{})
}

func incomeExpenseData(c *gin.Context) {
	sql.HttpDataById(c, &model.BankIncomeExpense{})
}

// FuturesFeeList /**费用（定金、尾款、税款）
func incomeExpenseList(c *gin.Context) {
	sql.HttpList(c, &[]model.BankIncomeExpense{}, func(db *gorm.DB) *gorm.DB {
		if att := c.Query("type"); att != "" {
			db = db.Where("type = ?", att)
		}
		db = db.Preload("BankStatement", func(db *gorm.DB) *gorm.DB {
			if att := c.Query("function"); att != "" {
				db = db.Where("bank_statement.function = ?", att).
					Select("bank_statement.*,bank_account.bank,bank_account.account_name,bank_account.card_number,bank_flow.date").
					Joins("left join bank_account ON bank_statement.account_id = bank_account.id").
					Joins("left join bank_flow ON bank_statement.bank_flow_id = bank_flow.id")
			}
			return db
		})
		return db
	})
}
